package com.dongrj.framework.web.webclient;

import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import org.springframework.web.reactive.function.client.WebClient;

public class WebClientConfig {


    @Bean
    public WebClient webClient() {
        return WebClient
                .builder()
                .baseUrl("http://localhost")
                .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
                .filter(WebClientFilter.logRequest())
                .filter(WebClientFilter.logResponse())
                .exchangeStrategies(exchangeStrategies())
                .build();
    }

    public ExchangeStrategies exchangeStrategies() {
        return ExchangeStrategies.builder().codecs(clientCodecConfigurer -> clientCodecConfigurer.defaultCodecs().maxInMemorySize(16 * 1024 * 1024)).build();
    }
}
